<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html>

<html lang="en">
<head>
<%@ include file="/common/common-css.jsp"%>

</head>
<body class="no-skin" style="display:none;">
        
<%@ include file="/common/common-js.jsp" %>

<div class="row">
	<div class="form-group col-sm-12">
		<label class="col-sm-2 control-label"  for="channel">数量:</label>
		<div class="input-group col-sm-10">
			<input class="form-control" id="costnum" />
		</div>
	</div>
	<div class="form-group col-xs-12">
		<label class="col-sm-2 control-label"  for="channel">违章:</label>
		<div class="input-group col-sm-6">
			<input class="form-control" id="wznum" value="0" />
		</div>
	</div>
	<div class="form-group col-xs-12">
		<label class="col-sm-2 control-label"  for="channel">渠道:</label>
		<div class="input-group col-sm-6">
			<s:select id="channel" name="channel" list="%{channelList}" listKey="channel_code" listValue="channel_name" class="form-control">
			</s:select>
		</div>
	</div>
</div>

<button class="btn  btn-success no-border" name="btn-save" id="btn-save">
		<i class="ace-icon fa fa-floppy-o bigger-160"></i> 修改
</button>
<button class="btn  btn-success no-border" name="btn-delete" id="btn-delete">
		<i class="ace-icon fa fa-floppy-o bigger-160"></i> 删除
</button>

<script>

function getQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
	var r = window.location.search.substr(1).match(reg);
	if (r != null) return decodeURI(r[2]); return null;
}

var channel = getQueryString('channel');
var sourceid = getQueryString("sourceid");

jQuery(function() {
	$('#channel option').each(function(){
		var txt = $(this).text();
		if(txt==channel){
			$(this).prop('selected',true);
			return false;
		};
		$('body').show();
	});
	$("#btn-save").bind("click",function() {
		$("#btn-save").attr("disabled","disabled");
		if($("#costnum").text() == null){
			$("#btn-save").removeAttr("disabled");
			return;
		}
		var channel = $("#channel").val();
		var cost = $("#costnum").val();
		var wznum = $('#wznum').val();
		$("#btn-save").attr("disabled","disabled");
			 $.ajax({
				 url: ctx + "/spread/editRecordRequest.action?sourceid="+sourceid+"&channel="+channel+"&cost="+cost+"&wznum="+wznum,
				 dataType:"json",
				 success: function(data){
					if (data.result.status != 1) {
						alert(data.result.msg);
					} else {
						parent.parent['__extdialog_active'].dialog('close');
						parent.main_frame.query_any();
					}
				}
		});
	});
	$("#btn-delete").bind("click",function() {
		$("#btn-delete").attr("disabled","disabled");
		if($("#costnum").text() == null){
			$("#btn-delete").removeAttr("disabled");
			return;
		}
		$("#btn-delete").attr("disabled","disabled");
			 $.ajax({
				 url: ctx + "/spread/delrecord.action?sourceid="+sourceid,
				 dataType:"json",
				 success: function(data){							 
					if(data.result.status != 1){
						alert(data.result.msg);
					}else{
						parent.parent['__extdialog_active'].dialog('close');
						parent.main_frame.query_any();	
					}
				}
		});
	});
});
</script>
</body>
</html>